package com.example.statistics.ui.ysy

import android.os.Bundle
import com.example.statistics.R
import com.example.statistics.bean.ysy.YsyProductBean
import com.example.statistics.common.BaseLoadingListActivity
import com.example.statistics.net.UrlConfig
import com.example.statistics.utils.Constants
import com.example.statistics.utils.activityFinish
import com.example.statistics.utils.activityForResult
import com.jhj.slimadapter.SlimAdapter
import com.jhj.slimadapter.holder.ViewInjector

class ProductListActivity : BaseLoadingListActivity<YsyProductBean>() {

    var action: String = ""

    override val title: String
        get() = "商品"

    override val url: String
        get() = UrlConfig.YSY_PRODUCT_LIST

    override val itemLayoutRes: Int
        get() = R.layout.list_item_common_display

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        action = intent.getStringExtra(Constants.ACTION).orEmpty()
        topBarRightImage {
            activityForResult<ProductAddActivity>() {
                refresh()
            }
        }
    }

    override fun itemViewConvert(adapter: SlimAdapter, injector: ViewInjector, bean: YsyProductBean, position: Int) {
        injector.text(R.id.tv_title, bean.name).text(R.id.tv_subtitle, bean.number.toString()).text(R.id.tv_bottom_right, bean.specification)
            .clicked {
                if (action == Constants.SELECTOR) {
                    activityFinish(Constants.DATA to bean)
                }
            }
    }
}